package com.gduf.lsm.controller;

import com.gduf.lsm.common.Result;
import com.gduf.lsm.entity.Mental;
import com.gduf.lsm.pojo.dto.JoinStatusDTO;
import com.gduf.lsm.pojo.vo.MentalShowVO;
import com.gduf.lsm.service.MentalService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 心理健康信息表前端操作接口
 **/
@RestController
@RequestMapping("/mental")

public class MentalController {

    @Resource
    private MentalService mentalService;

    /**
     * 新增
     * @param mental
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody Mental mental) {
        int mentalId=mentalService.add(mental);
        System.out.println("*************"+mentalId);
        return Result.success(mentalId);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        mentalService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        mentalService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     * @param mental
     * @return
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody Mental mental) {
        mentalService.updateById(mental);
        return Result.success();
    }

    /**
     * 修改活动状态
     * @param joinStatusDTO
     * @return
     */
    @PutMapping("/updateStatus")
    public Result updateStatus(@RequestBody JoinStatusDTO joinStatusDTO){
        mentalService.updateStatus(joinStatusDTO);
        return Result.success();
    }

    /**
     * 根据ID查询
     * @param id
     * @return
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Mental mental = mentalService.selectById(id);
        return Result.success(mental);
    }

    /**
     * 查询单个所有
     * @param id
     * @return
     */
    @GetMapping("/selectAllById/{id}")
    public Result selectAllById(@PathVariable Integer id){
        MentalShowVO mentalShowVO=mentalService.selectAllById(id);
        return Result.success(mentalShowVO);
    }

    /**
     * 查询所有
     * @param mental
     * @return
     */
    @GetMapping("/selectAll")
    public Result selectAll(Mental mental ) {
        List<Mental> list = mentalService.selectAll(mental);
        return Result.success(list);
    }

    /**
     * 查询用户的心理健康表
     * @param userId
     * @return
     */
    @GetMapping("/selectByUserId/{userId}")
    public Result selectByUserId(@PathVariable Integer userId){
        List<MentalShowVO> list=mentalService.selectByUserId(userId);
        System.out.println("*******mentalUserList*********"+list);
        return Result.success(list);
    }

    /**
     * 分页查询
     * @param mental
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/selectPage")
    public Result selectPage(Mental mental,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<MentalShowVO> page = mentalService.selectPage(mental, pageNum, pageSize);
        return Result.success(page);
    }

}